/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.minierp.dao.StorehouseDao;
import com.minierp.dao.WorkCenterDao;
import com.minierp.err.PermissionDennyException;
import com.minierp.helper.EncCommonHelper;
import com.minierp.model.WorkCenter;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class WorkCenterMACtr extends MultiActionController {
	private WorkCenterDao workCenterDao;
	private StorehouseDao storehouseDao;
	private String listView;
	private String listForSelectView;

	public ModelAndView handleList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "WORK_CENT")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listView);
			List list = this.workCenterDao.getList(true);
			mv.addObject("list", list);
			mv.addObject("storehouseList", this.storehouseDao.getList(true));
			return mv;
		}
	}

	public ModelAndView handleDelete(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String retUrl = request.getParameter("from_url");
		ModelAndView mv = new ModelAndView("redirect:" + retUrl);
		WorkCenter p = (WorkCenter) this.workCenterDao.get(WorkCenter.class,
				Long.parseLong(request.getParameter("id")));
		if (p != null) {
			p.setEnabled("N");
			this.workCenterDao.update(p);
		}

		EncCommonHelper.setAlertMessage(request, "删除成功！");
		return mv;
	}

	public ModelAndView handleListForSelect(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listForSelectView);
		List list = this.workCenterDao.getList(true);
		mv.addObject("list", list);
		return mv;
	}

	public String getListView() {
		return this.listView;
	}

	public void setListView(String listView) {
		this.listView = listView;
	}

	public WorkCenterDao getWorkCenterDao() {
		return this.workCenterDao;
	}

	public void setWorkCenterDao(WorkCenterDao workCenterDao) {
		this.workCenterDao = workCenterDao;
	}

	public StorehouseDao getStorehouseDao() {
		return this.storehouseDao;
	}

	public void setStorehouseDao(StorehouseDao storehouseDao) {
		this.storehouseDao = storehouseDao;
	}

	public String getListForSelectView() {
		return this.listForSelectView;
	}

	public void setListForSelectView(String listForSelectView) {
		this.listForSelectView = listForSelectView;
	}
}